package com.lp.user.control;

import com.lp.common.Result;
import com.lp.common.base.BaseController;
import com.lp.user.dto.User;
import com.lp.user.service.UserService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.Date;

@RestController
@Api(value ="用户信息相关的api")
@RequestMapping(value = "/user")
public class UserController extends BaseController {
	@Resource(name = "userTestService")
	protected UserService userService;
	@Resource(name = "dataSource")
	private DataSource dataSource;
	@RequestMapping(value = "/getInfo", method = RequestMethod.GET)
	public User home() {
		return userService.getUserInfo();
		// return "Hello World test!";
	}
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ApiOperation(value="获取有用列表", notes="测试接口详细描述")
	@ApiResponses({
        @ApiResponse(code=200,message = "id有编号nickname昵称"),
        @ApiResponse(code=404,message="请求路径没有找到")
    })
	public Result list() {
		return userService.getUserInfos(null);
		// return "Hello World test!";
	}
	@ApiOperation(value="通过参数获取用户信息", notes="通过用户编号获取用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "用户编号", required = true, dataType = "integer",paramType="query" ),
	})
	@RequestMapping(value = "/getUser", method = RequestMethod.GET)
	public Result getUser(Integer id) {
		System.out.println(new Date());
		return userService.getUserInfo(id);
		// return "Hello World test!";
	}
	@ApiOperation(value="保存用户信息", notes="通过参数保存用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "roletype", value = "角色", required = true, dataType = "string",paramType="query" ),
		@ApiImplicitParam(name = "city", value = "城市", required = true, dataType = "string",paramType="query" ),
		@ApiImplicitParam(name = "nickname", value = "用户昵称", required = true, dataType = "string",paramType="query" ),
		@ApiImplicitParam(name = "enabled", value = "是否有效", required = true, dataType = "tinyint",paramType="query",defaultValue="1",allowableValues="1,0",example="1.有效0.无效")
		})
	@RequestMapping(value = "/saveUserInfo", method = RequestMethod.POST)
	public Result saveUserInfo(User uid) {

		Result result=userService.saveUserInfor(uid);
		 return result;
	}

	@ApiOperation(value="修改用户信息", notes="通过参数修改用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "用户编号", required = true, dataType = "integer",paramType="query" ),
			@ApiImplicitParam(name = "enabled", value = "是否有效", required = true, dataType = "tinyint",paramType="query",defaultValue="1",allowableValues="1,0",example="1.有效0.无效")
	})
	@RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
	public Result updateUserInfo(User uid) {

		Result result=userService.updateUserInfo(uid);
		return result;
	}
	@RequestMapping(value = "/redis", method = RequestMethod.GET)
	public Result test(Integer id) {
		String ids=id+"asss";
		Result r= userService.getUserInfo(id);
		redisClientTemplate.set(ids,r);
		r=redisClientTemplate.get(ids,Result.class);
		return r;
	}
	@RequestMapping(value = "/aaa", method = RequestMethod.GET)
	public Result aaa(Integer id) {
		Result r= userService.getList();

		return r;
	}
	@ApiOperation(value="分页查找客户信息描述", notes="分页查找客户信息")
	@ApiImplicitParams({

			@ApiImplicitParam(name = "currrentPage", value = "当前页数", required = true, dataType = "integer",paramType="query" )
	})
	@ApiResponses({
			@ApiResponse(code=200,message = "nextPage：下一个页<br>previousPage:上一页<br>count：总条数<br>pageTotal:总页数<br>end：1没有下一页0.还有下一页<br>dataCount当前页的记录数"),
	})
	@RequestMapping(value = "/page", method = RequestMethod.GET)
	public Result page(Integer currrentPage )throws Exception {

		return userService.getPage(currrentPage);
	}

}